SELECT * INTO #temp FROM ColorIndex WHERE 1 IS NULL
UNION
SELECT * FROM ColorIndex WHERE 1 IS NULL
GO

INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(0, 'grayNoFirstWF', 150, 150, 150)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(1, 'redCurrent', 255, 0, 0)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(2, 'blueFault800', 0, 0, 255)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(3, 'ltBluePickUp', 110, 150, 250)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(4, 'greenTrip', 0, 102, 0)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(5, 'greenOpen', 0, 255, 0)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(6, 'redSource', 200, 0, 0)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(7, 'tanPQ', 255, 170, 100)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(8, 'pinkFltPQ', 250, 5, 230)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(9, 'blackLOS', 0, 0, 0)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(10, 'orgSglPH', 255, 255, 0)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(11, 'aquaTBD', 5, 250, 250)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(12, 'dkGrayTBD', 250, 100, 0)
INSERT INTO #temp(ID, Color, Red, Green, Blue) VALUES(100, 'yada', 1, 1, 1)
GO

SET IDENTITY_INSERT ColorIndex ON
GO
MERGE INTO ColorIndex
USING #temp
ON ColorIndex.ID = #temp.ID
WHEN MATCHED THEN UPDATE SET
    ColorIndex.Color = #temp.Color,
    ColorIndex.Red = #temp.Red,
    ColorIndex.Green = #temp.Green,
    ColorIndex.Blue = #temp.Blue
WHEN NOT MATCHED THEN
    INSERT(ID, Color, Red, Green, Blue)
    VALUES(#temp.ID, #temp.Color, #temp.Red, #temp.Green, #temp.Blue);
GO
SET IDENTITY_INSERT ColorIndex OFF
GO

DROP TABLE #temp
GO

CREATE TABLE MATLABAnalytic
(
    ID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
    AssemblyName VARCHAR(MAX) NOT NULL,
    MethodName VARCHAR(MAX) NOT NULL,
    SettingSQL VARCHAR(MAX) NOT NULL DEFAULT '',
    LoadOrder INT NOT NULL DEFAULT 0
)
GO

UPDATE MatlabGroup SET Name = 'G1 Vector Plot' WHERE Name = 'G1 Research'
UPDATE MatlabGroup SET Name = 'G2 IEEE 1668 Ridethrough Plot' WHERE Name = 'G2 Switching'
UPDATE MatlabGroup SET Name = 'G3 Suspected Blown Fuse Plot' WHERE Name = 'G3 Faults'
UPDATE MatlabGroup SET Name = 'G4 Reserved' WHERE Name = 'G4 Power Quality'
UPDATE MatlabGroup SET Name = 'G5 Harmonics Plot' WHERE Name = 'G5 Artifacts/Harmonics'
UPDATE MatlabGroup SET Name = 'G6 MinMax Plot' WHERE Name = 'G6 MinMaxAvg/History'
UPDATE MatlabGroup SET Name = 'G7 State Change Plot' WHERE Name = 'G7 Reports'
UPDATE MatlabGroup SET Name = 'G8 Reserved' WHERE Name = 'G8 Predictive'
UPDATE MatlabGroup SET Name = 'G9 Reserved' WHERE Name = 'G9 Other'
GO

CREATE TABLE EventTag
(
    ID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
    Name VARCHAR(200) NOT NULL UNIQUE,
    Description VARCHAR(MAX) NULL,
    ShowInFilter BIT NOT NULL Default(1),
)
GO

CREATE TABLE EventEventTag
(
    ID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
    EventID INT NOT NULL REFERENCES Event(ID),
    EventTagID INT NOT NULL REFERENCES EventTag(ID),
    TagData VARCHAR(MAX) NULL
)
GO